package cn.zwz.modules.tel.controller;

import cn.zwz.common.utils.PageUtil;
import cn.zwz.common.utils.ResultUtil;
import cn.zwz.common.vo.PageVo;
import cn.zwz.common.vo.Result;
import cn.zwz.modules.tel.entity.AddressBook;
import cn.zwz.modules.tel.service.IAddressBookService;
import cn.zwz.modules.tel.utils.NullUtils;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 郑为中
 */
@Slf4j
@RestController
@Api(tags = "通讯录管理接口")
@RequestMapping("/zwz/addressBookExcel")
@Transactional
public class AddressBookExcelController {

    @Autowired
    private IAddressBookService iAddressBookService;

    @RequestMapping(value = "/excel", method = RequestMethod.GET)
    @ApiOperation(value = "通过id获取")
    public Result<AddressBook> excel() {
        String fileName = "D:\\1.xlsx";
        List<Book> list = new ArrayList<>();
        list.add(new Book().setName("A"));
        list.add(new Book().setName("B"));
        EasyExcel.write(fileName, Book.class).sheet("模板").doWrite(list);
        return new ResultUtil<AddressBook>().setSuccessMsg("OK");
    }

    @Data
    @Accessors(chain = true)
    private static class Book implements Serializable {

        @ExcelProperty("姓名")
        private String name;
    }
}
